package com.bluefox.system.redis.A01;

import com.bluefox.utils.RedisUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;

/**
 * @Author : 孙峰
 * @Description:
 * @Date : 2022/4/10  19:52
 */
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class StringTest01 {

    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    private static final ObjectMapper mapper = new ObjectMapper();


    @Test
    public void testPwBaseInfo() throws IOException {
        User user = new User();
        user.setAge(10);
        user.setName("sf");
        String s = mapper.writeValueAsString(user);
        stringRedisTemplate.opsForValue().set("sunfeng",s);
        String sunfeng = stringRedisTemplate.opsForValue().get("sunfeng");
        User user1 = mapper.readValue(sunfeng, User.class);
        System.out.println(user1);
    }
}
